package com.cloud.pole.user.service.authorized.impl;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cloud.pole.api.user.UserAuthorizedWxApi;
import com.cloud.pole.common.util.jwt.IJWTInfo;
import com.cloud.pole.common.util.jwt.JwtTokenUtil;
import com.cloud.pole.user.biz.authorized.UserAuthorizedWxBiz;
import com.cloud.pole.user.model.entity.authorized.UserAuthorizedWx;
import com.cloud.pole.user.service.authorized.UserAuthorizedWxService;
import lombok.extern.slf4j.Slf4j;

/*
*2019年4月26日
*cloud-user
*author:frank-chen
*/
@Service
@Slf4j
public class UserAuthorizedWxServiceImpl implements UserAuthorizedWxService {

	@Autowired
	private UserAuthorizedWxBiz userAuthorizedWxBiz;
	
	@Override
	public UserAuthorizedWxApi getUserAuthorizedWxApi(String token, Integer wxAppId) throws Exception {
		// TODO Auto-generated method stub
		IJWTInfo jwtInfo = JwtTokenUtil.getInfoFromToken(token);
		Long userId = Long.parseLong(jwtInfo.getId());
		
		UserAuthorizedWx user = userAuthorizedWxBiz.selectByUserId(userId, wxAppId);
		UserAuthorizedWxApi api = new UserAuthorizedWxApi();
		BeanUtils.copyProperties(user, api);
		return api;
	}
}
